package com.cbank.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.cbank.domain.UserAccount;
@Repository
public interface UserAccountDao {
	String ALL = "id,view_id,can_down_num,create_time,update_time,status";

	@Insert("insert into user_account(view_id,can_down_num,status) values("
			+ "#{viewId},#{canDownNum},#{status})")
	@Options(useGeneratedKeys = true)
    void insert(UserAccount obj);

	@Select("select " + ALL + " from user_account where id = #{id} and status = 1 limit 1")
    UserAccount getById(Long id);
	
	@Select("select " + ALL + " from user_account where user_id = #{uid} and status = 1 limit 1")
    UserAccount getByUserId(Long uid);

	@Select("select " + ALL + " from user_account where view_id = #{viewId} and status = 1 limit 1")
    UserAccount getByViewId(Long viewId);
	
	@Update("update user_account set can_down_num = #{canDownNum},status = #{status} where id = #{id} limit 1")
    void update(UserAccount o);

	@Select("select count(1) from user_account where status = 1")
    int getCount();
}
